package cn.web.demo.controller;

import cn.web.demo.model.CouresResult;
import cn.web.demo.model.CourseOrder;
import cn.web.demo.model.PageResult;
import cn.web.demo.model.Permission;
import cn.web.demo.service.impl.IPermissionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    IPermissionServiceImpl iPermissionService;

    @RequestMapping("/list")
    public String list(){
        //System.out.println("------");
        return "/permission/list";
    }
    @RequestMapping("/add")
    public String add(Model model){
        List<Permission> list=iPermissionService.findAllParentMenus();
        model.addAttribute("list",list);
        return "/permission/add";
    }

    @RequestMapping("/listJson")
    @ResponseBody
    public PageResult<Permission> orderjson(){
        PageResult<Permission> pageResult=new PageResult<>();
        pageResult.setData(iPermissionService.findAllPermission());
        return pageResult;
    }

    @RequestMapping("save")
    @ResponseBody
    public CouresResult save(Permission permission){
        CouresResult couresResult=new CouresResult();
        iPermissionService.save(permission);
        return couresResult;
    }

}
